﻿new Module('CobraCms.Js.ContentEditor', function () {
    var Class = Phosphor.Utilities.Class;

    var ContentEditorInstance = new Class({

        Form: {},

        initialize: function (options) {
            this.Form = $("#content-editor-form");
            this.InitializeWorkspace();
        },

        InitializeWorkspace: function () {
            this.Form.on('submit', this.SubmitForm.bind(this));
        },

        SubmitFormSuccess: function (data) {
            $("#workspace-zone").html(data);
        },

        SubmitFormError: function (jqHR, textStatus, errorThrown) {
            window.alert("uh oh");
        },

        SubmitForm: function (event) {
            event.preventDefault();
            var url = this.Form.attr("action");
            $.ajax(
                {
                    type: "POST",
                    url: url,
                    data: this.Form.serialize(),
                    success: this.SubmitFormSuccess.bind(this),
                    error: this.SubmitFormError.bind(this)
                });
            return false;
        }



    });

    this.Instance = {};

    this.Reload = function () {
        this.Instance = new ContentEditorInstance();
    }

});
